<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>绑定用户</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" type="text/css" href="/H5/css/sm.min.css"/>
    <link rel="stylesheet" type="text/css" href="/H5/css/reset.css?v=1"/>
</head>
<body>
<div class="page-group ms-controller" :controller="bind">
    <div class="page page-current">
        <header class="bar bar-nav">
            <a class="icon icon-left pull-left" href="javascript:window.history.go(-1);"></a>
            <a class="icon icon-home pull-right" href="/H5"></a>
            <h1 class="title">绑定用户</h1>
        </header>
        <div class="content">
            <div :if="@type==1" class="list-block">
                <ul class="block-ul">
                    <li>
                        <div class="item-content">
                            <div class="item-inner">
                                <div class="item-title label">老会员账户名</div>
                                <div class="item-input">
                                    <input type="text" :duplex="old_username" placeholder="请输老会员账户名">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-inner">
                                <div class="item-title label">确认密码</div>
                                <div class="item-input">
                                    <input type="password" :duplex="confirmPassword" placeholder="请输入原账户密码">
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
                <div class="content-block">
                    <div class="row">
                        <div class="col-50" style="width:95%;"><a href="javascript:;" :on-click="@submit"
                                                                  class="button button-big button-fill button-danger">确认并提交</a>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
<script type='text/javascript' src='/H5/js/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/avalon.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/simpleStorage.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/mall.js?v=10' charset='utf-8'></script>
<script>
    var password = avalon.define({
        $id: "bind",
        type: Mall.parseUrl(window.location.href).type,
        old_username: "",
        confirmPassword: "",
        submit: function () {

            if (!password.old_username) {
                $.toast("请输入老会员账号", 2000, "warning");
                return
            }
            if (!password.confirmPassword) {
                $.toast("请输入新密码", 2000, "warning");
                return
            }

            $.prompt("请输入原登录密码", function (value) {
                var postData = {
                    old_password: value,
                    old_username: password.old_username,
                    confirm_password: password.confirmPassword
                };
                Mall.request("/api/BindWx", postData)
                        .always(function (data) {
                            if (data.error_code == 0) {
                                $.toast("绑定成功，请重新登录", 1000, "success", function () {
                                    window.location.href="/wap/index/wxReg";
                                })
                            }
                            else {
                                $.alert(data.error_msg);
                            }
                        })
            });
        },
        logout: function(){
            Mall.request("/api/Logout")
                    .always(function(data){
                        if( data.error_code == 0 ){
                            simpleStorage.set('token', undefined);
                            simpleStorage.set('isOauth', undefined);
                            window.location.href='/H5/login';
                        }
                    })
        },
        jump: function (e, o) {
            if (e) {
                if (!$("a.type" + e).hasClass("active")) {
                    $(".tab-link").removeClass("active");
                    $("a.type" + e).addClass("active");
                    if (o) {
                        window.history.replaceState(null, null, window.location.href.split("=")[0] + "=" + e);
                    }
                }
                password.type = e
            }
        }
    })
    password.jump(password.type);
    avalon.scan(document.body);
</script>
</body>
</html>
